package com.btex.app.treaty;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.btex.app.BaseActivity;
import com.btex.app.R;
import com.btex.app.treaty.dialog.LeverSetCounterDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CounterActivity extends BaseActivity {

    @BindView(R.id.activity_counter_but_zhang)
    Button mActivityCounterButZhang;
    @BindView(R.id.activity_counter_but_type)
    Button mActivityCounterButType;
    @BindView(R.id.activity_counter_tv_shouyi)
    TextView mActivityCounterTvShouyi;
    @BindView(R.id.activity_counter_tv_mubiao)
    TextView mActivityCounterTvMubiao;
    @BindView(R.id.activity_counter_tv_qiangping)
    TextView mActivityCounterTvQiangping;
    @BindView(R.id.activity_counter_tv_heyue_type)
    TextView mActivityCounterTvHeyueType;
    @BindView(R.id.activity_counter_but_long)
    Button mActivityCounterButLong;
    @BindView(R.id.activity_counter_but_short)
    Button mActivityCounterButShort;
    @BindView(R.id.activity_counter_but_sure)
    Button mActivityCounterButSure;
    @BindView(R.id.activity_tv_leverage)
    TextView mActivityTvLeverage;
    @BindView(R.id.editText_kaicang)
    EditText mEditTextKaicang;
    @BindView(R.id.editText_pingcang)
    EditText mEditTextPingcang;
    @BindView(R.id.activity_counter_lin_shouyi)
    LinearLayout mActivityCounterLinShouyi;
    @BindView(R.id.activity_counter_lin_type)
    LinearLayout mActivityCounterLinType;
    @BindView(R.id.activity_counter_include)
    LinearLayout mActivityCounterInclude;
    @BindView(R.id.activity_counter_but_shouyilv)
    Button mActivityCounterButShouyilv;
    @BindView(R.id.activity_counter_but_shouyi)
    Button mActivityCounterButShouyi;
    @BindView(R.id.include_counter_shouyi)
    LinearLayout mIncludeCounterShouyi;
    @BindView(R.id.include_counter_shouyilv)
    LinearLayout mIncludeCounterShouyilv;
    @BindView(R.id.editText_pingcang_number)
    EditText mEditTextPingcangNumber;
    @BindView(R.id.activity_counter_viewpager)
    ViewPager mActivityCounterViewpager;
    private String mData = "10";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_counter);
        ButterKnife.bind(this);

        mActivityCounterButZhang.setSelected(true);
        mActivityCounterButLong.setSelected(true);
        mActivityCounterTvShouyi.setSelected(true);
        mActivityCounterButShouyilv.setSelected(true);
    }

    @Override
    public void setData() {

    }

    @Override
    public void onClick(View v) {

    }

    @OnClick({R.id.activity_counter_but_zhang, R.id.activity_counter_but_type, R.id.activity_counter_but_short, R.id.activity_counter_but_long, R.id.activity_counter_tv_shouyi, R.id.activity_counter_tv_mubiao, R.id.activity_counter_tv_qiangping, R.id.activity_counter_but_sure, R.id.activity_tv_leverage, R.id.activity_counter_imag_back, R.id.activity_counter_but_shouyilv, R.id.activity_counter_but_shouyi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_counter_but_zhang:
                SetStat();
                mActivityCounterButZhang.setSelected(true);

                break;
            case R.id.activity_counter_but_type:
                SetStat();
                mActivityCounterButType.setSelected(true);
                break;

            case R.id.activity_counter_but_short:
                SetButStat();
                mActivityCounterButShort.setSelected(true);
                break;

            case R.id.activity_counter_but_long:
                SetButStat();
                mActivityCounterButLong.setSelected(true);
                break;

            case R.id.activity_counter_tv_shouyi:
                mActivityCounterInclude.setVisibility(View.GONE);
                mActivityCounterLinType.setVisibility(View.VISIBLE);
                SetTvStat();
                mActivityCounterTvShouyi.setSelected(true);

                break;

            case R.id.activity_counter_tv_mubiao:

                mActivityCounterInclude.setVisibility(View.VISIBLE);
                mActivityCounterLinType.setVisibility(View.GONE);

                SetTvStat();
                mActivityCounterTvMubiao.setSelected(true);
                break;

            case R.id.activity_counter_tv_qiangping:
                mActivityCounterInclude.setVisibility(View.GONE);
                mActivityCounterLinType.setVisibility(View.VISIBLE);
                SetTvStat();
                mActivityCounterTvQiangping.setSelected(true);
                break;

            case R.id.activity_counter_but_sure:
                mActivityCounterLinShouyi.setVisibility(View.VISIBLE);
                getEarnings();
                break;

            case R.id.activity_tv_leverage:

                LeverSetCounterDialog leverSetCounterDialog = new LeverSetCounterDialog(this);
                leverSetCounterDialog.getValue(new LeverSetCounterDialog.getValueLIstener() {


                    @Override
                    public void get(String data) {
                        mData = data;
                    }
                });
                break;

            case R.id.activity_counter_imag_back:

                finish();
                break;

            case R.id.activity_counter_but_shouyilv:
                setIncludeState();
                mActivityCounterButShouyilv.setSelected(true);
                mIncludeCounterShouyi.setVisibility(View.VISIBLE);
                mIncludeCounterShouyilv.setVisibility(View.GONE);
                break;

            case R.id.activity_counter_but_shouyi:

                setIncludeState();
                mActivityCounterButShouyi.setSelected(true);
                mIncludeCounterShouyi.setVisibility(View.GONE);
                mIncludeCounterShouyilv.setVisibility(View.VISIBLE);

                break;
        }


    }


    public void SetStat() {
        mActivityCounterButZhang.setSelected(false);
        mActivityCounterButType.setSelected(false);

    }

    public void SetButStat() {
        mActivityCounterButLong.setSelected(false);
        mActivityCounterButShort.setSelected(false);
    }


    public void SetTvStat() {
        mActivityCounterTvShouyi.setSelected(false);
        mActivityCounterTvMubiao.setSelected(false);
        mActivityCounterTvQiangping.setSelected(false);
    }

    public void setIncludeState() {
        mActivityCounterButShouyilv.setSelected(false);
        mActivityCounterButShouyi.setSelected(false);
    }

    /**
     * 计算收益
     */
    public void getEarnings() {
//        方向*（1/开仓价格-1/平仓价格）*仓位   反向
//        方向*（平仓-开仓）仓位   正向

        String kaicang = mEditTextKaicang.getText().toString().trim();
        String pingcang = mEditTextPingcang.getText().toString().trim();
        String PingcangNumber = mEditTextPingcangNumber.getText().toString().trim();

        if (TextUtils.isEmpty(mData)) {
            Toast.makeText(cxt, "杠杆不能为空", Toast.LENGTH_SHORT).show();
        } else {
            double shouYiLv = (1 / Double.valueOf(kaicang) - 1 / Double.valueOf(pingcang)) / (1 / Double.valueOf(kaicang)) * Double.valueOf(PingcangNumber) * Double.valueOf(mData);
//        乘杠杆和开仓数量
            Log.i("weijfowijfowejfw", shouYiLv + "");
        }


    }

}
